#include "gtest/gtest.h"
#include <mockcpp/mokc.h>
#include <mockcpp/mockcpp.hpp>

#include <vector>
#include <iostream>

#include "topoinfo_struct.h"
#include "log.h"
#include "checker.h"
#include "virtual_topo.h"
#include "testcase_utils.h"
#include "coll_reduce_scatter_executor.h"

using namespace hccl;

std::vector<string> reduceScatterAlgName = {
    "ReduceScatterDeterExecutor",
    "ReduceScatterMeshExecutor",
    "ReduceScatterMeshOpbasePipelineExecutor",
    "ReduceScatterRingExecutor",
};

class ReduceScatterTest : public testing::Test {
protected:
    static void SetUpTestCase()
    {
        std::cout << "ReduceScatterTest set up." << std::endl;
    }

    static void TearDownTestCase()
    {
        std::cout << "ReduceScatterTest tear down." << std::endl;
    }

    virtual void SetUp()
    {
        const ::testing::TestInfo* const test_info = ::testing::UnitTest::GetInstance()->current_test_info();
        std::string caseName = "analysis_result_" + std::string(test_info->test_case_name()) + "_" + std::string(test_info->name());
        Checker::SetDumpFileName(caseName);
    }

    virtual void TearDown()
    {
        Checker::SetDumpFileName("analysis_result");
        GlobalMockObject::verify();
        // 这边每个case执行完成需要清理所有的环境变量，如果有新增的环境变量，需要在这个函数中进行清理
        ClearHcclEnv();
    }
};

TEST_F(ReduceScatterTest, reduce_scatter_test)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 2, 1);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);

    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_test_loop)
{
    RankTable_For_LLT gen;
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    setenv("HCCL_DETERMINISTIC", "true", 1);
    HcclResult ret;
    for (int i = 1; i <= 2; i++) {
        for (int j = 1; j <= 8; j++) {
            Checker checker;
            RankTable_t ranktable;
            TopoMeta topoMeta;
            gen.GenTopoMeta(topoMeta, 1, i, j);
            gen.GenRankTable(topoMeta, ranktable);
            ret = checker.Check(testOpParam, ranktable, topoMeta);
            EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
        }
    }
}

TEST_F(ReduceScatterTest, reduce_scatter_executor_opbase_ReduceScatterDeterExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 10000000;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterDeterExecutor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_executor_offload_ReduceScatterMeshExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);
    setenv("HCCL_DETERMINISTIC", "true", 1);
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterMeshExecutor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_executor_offload_ReduceScatterRingExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterRingExecutor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

// 仅测试用，不同算法限制不同
TEST_F(ReduceScatterTest, reduce_scatter_executor_test_loop)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;

    for (int i = 0; i < reduceScatterAlgName.size(); i++) {
        testOpParam.algName = reduceScatterAlgName[i];
        Checker checker;
        HcclResult ret;
        checker.CloseRankMemCheck();
        ret = checker.Check(testOpParam, ranktable, topoMeta);
        if (ret == HcclResult::HCCL_SUCCESS) {
            std::cout << reduceScatterAlgName[i] + " run successed" << std::endl;
        } else {
            std::cout << reduceScatterAlgName[i] + " run failed" << std::endl;
        }
        EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
    }
}

TEST_F(ReduceScatterTest, reduce_scatter_ReduceScatterComm_test)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta {{{0, 1}, {0, 1, 2}}};
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterComm";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_ReduceScatterSingleExecutor_test)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 1);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;

    testOpParam.algName = "ReduceScatterSingleExecutor";
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910A_offload_ReduceScatterMeshExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 4);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_910;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterMeshExecutor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910A_offload_ReduceScatterRingExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_910;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterRingExecutor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910A_offload_ReduceScatterComm)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta {{{2, 5}, {0, 1, 2}}};
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_910;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterComm";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910A_opbase_ReduceScatterMeshExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 4);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterMeshExecutor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910A_opbase_ReduceScatterRingExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterRingExecutor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910A_opbase_ReduceScatterComm)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta {{{2, 5}, {0, 1, 2}}};
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterComm";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

// 适配910_93算法
TEST_F(ReduceScatterTest, reduce_scatter_910_93_opbase_ReduceScatterFastDoubleRingFor91093Executor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);
    setenv("HCCL_DETERMINISTIC", "true", 1);
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterFastDoubleRingFor91093Executor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910_93_opbase_ReduceScatterFastDoubleRingFor91093Executor_tbe)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 2, 8);
    gen.GenRankTable(topoMeta, ranktable);
    setenv("HCCL_DETERMINISTIC", "true", 1);
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 4*1024*1024;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT64;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterFastDoubleRingFor91093Executor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910_93_offload_ReduceScatterFastDoubleRingFor91093Executor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterFastDoubleRingFor91093Executor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}


TEST_F(ReduceScatterTest, reduce_scatter_910_93_opbase_AlignedReduceScatterDoubleRingFor91093Executor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AlignedReduceScatterDoubleRingFor91093Executor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910_93_opbase_MultiSuperPod_2_6_2_ReduceScatterDoubleRingFor91093Executor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 2, 6, 2);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910_93_opbase_MultiSuperPod_4_3_2_ReduceScatterDoubleRingFor91093Executor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 4, 3, 2);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910_93_offload_AlignedReduceScatterDoubleRingFor91093Executor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AlignedReduceScatterDoubleRingFor91093Executor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910_93_offload_ReduceScatterDoubleRingConcurrentExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    setenv("HCCL_CONCURRENT_ENABLE", "1", 1);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterDoubleRingConcurrentExecutor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910_93_opbase_ReduceScatterDoubleRingConcurrentExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    setenv("HCCL_CONCURRENT_ENABLE", "1", 1);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterDoubleRingConcurrentExecutor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_310P3_opbase_ReduceScatterRing)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_310P3;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterRing";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_310P3_offload_ReduceScatterRing)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_310P3;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterRing";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910_93_opbase_accuracy_double_pod)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 2, 1, 16);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 1024 * 1024;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_FP32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910_93_retry_inplace_presync_case_level0)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 16);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 134217728 * 2;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_FP32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AlignedReduceScatterDoubleRingFor91093Executor";
    testOpParam.algOpContext.opRetryHandler.isInplacePreSync = true;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    // PreSync会memcopy一段无效数据以占满所有端口，从而达到检测断链的效果，所以数据本身没有被使用，是允许的。
    // 且PreSync不执行任何reduce scatter算法。
}

TEST_F(ReduceScatterTest, reduce_scatter_910_93_retry_inplace_presync_case_level1)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 8, 1);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 134217728 * 2;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_FP32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AlignedReduceScatterDoubleRingFor91093Executor";
    testOpParam.algOpContext.opRetryHandler.isInplacePreSync = true;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    // PreSync会memcopy一段无效数据以占满所有端口，从而达到检测断链的效果，所以数据本身没有被使用，是允许的。
    // 且PreSync不执行任何reduce scatter算法。
}

TEST_F(ReduceScatterTest, reduce_scatter_910_93_retry_inplace_presync_case_level2)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 2, 1, 1);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 134217728 * 2;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_FP32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "AlignedReduceScatterDoubleRingFor91093Executor";
    testOpParam.algOpContext.opRetryHandler.isInplacePreSync = true;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    // PreSync会memcopy一段无效数据以占满所有端口，从而达到检测断链的效果，所以数据本身没有被使用，是允许的。
    // 且PreSync不执行任何reduce scatter算法。
}
// 适配910_93算法
TEST_F(ReduceScatterTest, reduce_scatter_smallcount_multiserver_test)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 2, 4);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;

    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);

    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_910_93_offload_ReduceScatterMeshAtomic)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.algName = "ReduceScatterMeshAtomic";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_E_PARA);
}

TEST_F(ReduceScatterTest,
    reduce_scatter_910_93_offload_ReduceScatterSemiRingExecutor_inlineReduce_singleServer)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8); // rankSize = 16, 14, 12, 10, 8, 6, 4
    gen.GenRankTable(topoMeta, ranktable);
 
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "ReduceScatterSemiRingExecutor";
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.aicpuUnfoldMode = true;
 
    Checker checker;
    HcclResult ret;
    // checker.EnableTaskPrint();
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest,
    reduce_scatter_910_93_offload_ReduceScatterSemiRingExecutor_inlineReduce_singleServer_oddNum)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 8);
    gen.GenRankTable(topoMeta, ranktable);
 
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 55;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.algName = "ReduceScatterSemiRingExecutor";
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.aicpuUnfoldMode = true;
 
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}
 
TEST_F(ReduceScatterTest, reduce_scatter_910_93_offload_ReduceScatterSemiRingExecutor_tbeReduce)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 12); // rankSize = 16, 14, 12, 10, 8, 6, 4
    gen.GenRankTable(topoMeta, ranktable);
 
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT64;
    testOpParam.algName = "ReduceScatterSemiRingExecutor";
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.aicpuUnfoldMode = true;
 
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

#if 0 // 待解决资源申请后使用
TEST_F(ReduceScatterTest,
    reduce_scatter_910_93_offload_ReduceScatterSemiRingExecutor_inlineReduce_MultiServer)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 4, 12); // serverSize = 2, 6, 4, 8*8, 16*2
    gen.GenRankTable(topoMeta, ranktable);
    setenv("HCCL_ALGO", "level0:ring;level1:NHR", 1);
 
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "ReduceScatterSemiRingExecutor";
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.aicpuUnfoldMode = true;
 
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest,
    reduce_scatter_910_93_offload_ReduceScatterSemiRingExecutor_inlineReduce_MultiSuPod)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 2, 4, 8);
    gen.GenRankTable(topoMeta, ranktable);
    setenv("HCCL_ALGO", "level0:ring;level1:NHR", 1);
 
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT32;
    testOpParam.algName = "ReduceScatterSemiRingExecutor";
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.aicpuUnfoldMode = true;
 
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}
 
TEST_F(ReduceScatterTest,
    reduce_scatter_910_93_offload_ReduceScatterSemiRingExecutor_tbeReduce_MultiServer)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 4, 12);
    gen.GenRankTable(topoMeta, ranktable);
    setenv("HCCL_ALGO", "level0:ring;level1:NHR", 1);
 
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT64;
    testOpParam.algName = "ReduceScatterSemiRingExecutor";
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.aicpuUnfoldMode = true;
 
    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}
#endif

TEST_F(ReduceScatterTest, reduce_scatter_ax_4server_16p)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 4, 16);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.devtype = DevType::DEV_TYPE_910B;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;

    Checker checker;
    HcclResult ret;
    checker.CloseRankMemCheck();
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_mix_ReduceScatterMixExecutor)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;

    /***** GenTopoMeta Start *****/
    TopoMeta topoMeta;
    SuperPodMeta superPodMeta;
    ServerMeta serverMeta910B;
    u32 rankNum910B = 16;
    for (u32 k = 0; k < rankNum910B; k++) {
        serverMeta910B.push_back(k);
    }
    superPodMeta.push_back(serverMeta910B);
    ServerMeta serverMeta91093;
    u32 rankNum91093 = 16;
    for (u32 k = 0; k < rankNum91093; k++) {
        serverMeta91093.push_back(k);
    }
    superPodMeta.push_back(serverMeta91093);

    topoMeta.push_back(superPodMeta);
    /***** GenTopoMeta End *****/

    /***** GenRankTable Start *****/
    gen.GenRankTable(topoMeta, ranktable);
    for (auto &rankInfo : ranktable.rankList) {
        if (rankInfo.serverIdx == 0) {
            rankInfo.deviceInfo.deviceType = DevType::DEV_TYPE_910B;
        } else {
            rankInfo.deviceInfo.deviceType = DevType::DEV_TYPE_910_93;
        }
    }
    /***** GenRankTable End *****/

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_FP32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devTypes.insert(DevType::DEV_TYPE_910B);
    testOpParam.devTypes.insert(DevType::DEV_TYPE_910_93);

    Checker checker;
    HcclResult ret;
    checker.CloseRankMemCheck();
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_mix_ReduceScatterMixExecutor_deter)
{
    setenv("HCCL_DETERMINISTIC", "true", 1);
    RankTable_t ranktable;
    RankTable_For_LLT gen;

    /***** GenTopoMeta Start *****/
    TopoMeta topoMeta;
    SuperPodMeta superPodMeta;
    ServerMeta serverMeta910B;
    u32 rankNum910B = 16;
    for (u32 k = 0; k < rankNum910B; k++) {
        serverMeta910B.push_back(k);
    }
    superPodMeta.push_back(serverMeta910B);
    ServerMeta serverMeta91093;
    u32 rankNum91093 = 16;
    for (u32 k = 0; k < rankNum91093; k++) {
        serverMeta91093.push_back(k);
    }
    superPodMeta.push_back(serverMeta91093);

    topoMeta.push_back(superPodMeta);
    /***** GenTopoMeta End *****/

    /***** GenRankTable Start *****/
    gen.GenRankTable(topoMeta, ranktable);
    for (auto &rankInfo : ranktable.rankList) {
        if (rankInfo.serverIdx == 0) {
            rankInfo.deviceInfo.deviceType = DevType::DEV_TYPE_910B;
        } else {
            rankInfo.deviceInfo.deviceType = DevType::DEV_TYPE_910_93;
        }
    }
    /***** GenRankTable End *****/

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_FP32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devTypes.insert(DevType::DEV_TYPE_910B);
    testOpParam.devTypes.insert(DevType::DEV_TYPE_910_93);

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_mix_ReduceScatterMixExecutor_deter_comm)
{
    setenv("HCCL_DETERMINISTIC", "true", 1);
    RankTable_t ranktable;
    RankTable_For_LLT gen;

    /***** GenTopoMeta Start *****/
    TopoMeta topoMeta;
    SuperPodMeta superPodMeta;
    ServerMeta serverMeta910B;
    u32 rankNum910B = 1;
    for (u32 k = 0; k < rankNum910B; k++) {
        serverMeta910B.push_back(k);
    }
    superPodMeta.push_back(serverMeta910B);
    ServerMeta serverMeta91093;
    u32 rankNum91093 = 1;
    for (u32 k = 0; k < rankNum91093; k++) {
        serverMeta91093.push_back(k);
    }
    superPodMeta.push_back(serverMeta91093);

    topoMeta.push_back(superPodMeta);
    /***** GenTopoMeta End *****/

    /***** GenRankTable Start *****/
    gen.GenRankTable(topoMeta, ranktable);
    for (auto &rankInfo : ranktable.rankList) {
        if (rankInfo.serverIdx == 0) {
            rankInfo.deviceInfo.deviceType = DevType::DEV_TYPE_910B;
        } else {
            rankInfo.deviceInfo.deviceType = DevType::DEV_TYPE_910_93;
        }
    }
    /***** GenRankTable End *****/

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_FP32;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devTypes.insert(DevType::DEV_TYPE_910B);
    testOpParam.devTypes.insert(DevType::DEV_TYPE_910_93);

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_aiv_a3_ReduceScatterMeshAivExecutor)
{
    MOCKER(GetExternalInputHcclAivMode).stubs().will(returnValue(true));

    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 1, 16);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.aicpuUnfoldMode = true;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_smallcount_rhd_test)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 2, 3);
    gen.GenRankTable(topoMeta, ranktable);

    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_FP32;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);

    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_ReduceScatterRingFor91093Executor_NHR)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 2, 2, 8);
    gen.GenRankTable(topoMeta, ranktable);

    setenv("HCCL_ALGO", "level0:NA;level1:NHR;level2:NHR", 1);
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.algName = "ReduceScatterRingFor91093Executor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_ReduceScatterRingFor91093Executor_NB)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 2, 2, 8);
    gen.GenRankTable(topoMeta, ranktable);

    setenv("HCCL_ALGO", "level0:NA;level1:NB;level2:NB", 1);
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OPBASE;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;
    testOpParam.algName = "ReduceScatterRingFor91093Executor";

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}

TEST_F(ReduceScatterTest, reduce_scatter_A3_2Server1Rank_nb_test)
{
    RankTable_t ranktable;
    RankTable_For_LLT gen;
    TopoMeta topoMeta;
    gen.GenTopoMeta(topoMeta, 1, 2, 1);
    gen.GenRankTable(topoMeta, ranktable);

    setenv("HCCL_ALGO", "level0:NA;level1:NB", 1);
    TestOpParam testOpParam;
    testOpParam.opType = HcclCMDType::HCCL_CMD_REDUCE_SCATTER;
    testOpParam.tag = "ReduceScatter";
    testOpParam.opMode = OFFLOAD;
    testOpParam.DataDes.count = 100;
    testOpParam.DataDes.dataType = HcclDataType::HCCL_DATA_TYPE_INT8;
    testOpParam.reduceType = HcclReduceOp::HCCL_REDUCE_SUM;
    testOpParam.devtype = DevType::DEV_TYPE_910_93;

    Checker checker;
    HcclResult ret;
    ret = checker.Check(testOpParam, ranktable, topoMeta);
    EXPECT_EQ(ret, HcclResult::HCCL_SUCCESS);
}